#include <stdio.h>
#include <stdlib.h>
#define SIZE 8

/* function declaration */

void print_menu();
void changevalues(char*, char*, char*);
void checkrotate();
void calculatearray();
float maxminavg(int, int);

/* main function */

int main(){
	int key, cont = 1;
	print_menu();
	while  (cont != 0){
		scanf("%d", &key);
		switch (key){
			case 1:{
				system("cls");
				checkrotate();
				print_menu();
				break;
				   }

			case 2:{
				system("cls");
				calculatearray();
				print_menu();
				break;
				   }
			default:{
				system("cls");
				return 0;
					}
		}
	}
}


void print_menu(){
	printf("Welcome to Exercise \n");
	printf("1- Rotate values in three chars \n");
	printf("2- Calculate Min, Max and Average in array\n");
	printf("0- Exit \n");
}

void checkrotate(){
	char a = 'a', b = 'b', c = 'c';
	printf("%c, %c, %c \n", a , b, c);
	changevalues(&a, &b, &c);
	printf("%c, %c, %c \n", a , b, c);

}
void changevalues(char *a, char *b, char *c){
	char temp;
	temp = *a;
	*a = *b;
	*b = *c;
	*c = temp;
	return;
}

void calculatearray(){
	float avg;
	int min, max;
	int arr[SIZE] = {1231,3333,5324,248,5434,35435,96553,13223};
	avg = maxminavg(arr, SIZE, &max, &min);
	printf("Arrray average result: %2.2lf\n", avg);
	
}

float maxminavg(int arr[], int size, int* max, int* min){
	
	int i, avg;
	*max = arr[0], *min = arr[0];
	for(i = 0; i < size; i++){
		if(arr[i] > *max){
			*max = arr[i];
		}
		else if(arr[i] < *min){
			*min = arr[i];
		}
	}
	avg = (*max + *min) / 2;
	return avg;
	
};
